using NLog;

namespace WorkerService.App1.Workers;

public class HttpWorker : BackgroundService
{
    private readonly ILogger<HttpWorker> _logger;
    private readonly HttpClient _httpClient;
    private Logger logger = LogManager.GetCurrentClassLogger();

    public HttpWorker(ILogger<HttpWorker> logger, HttpClient httpClient)
    {
        _logger = logger;
        _httpClient = httpClient;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        await Task.Run(() =>
        {
            Thread.Sleep(3000);

            var response = _httpClient.GetStringAsync("https://www.baidu.com").Result;
            // _logger.LogError($"response: {response}");
            logger.Error($"response: {response}");
        });
    }
}